package com.yuan.ssm.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yuan.ssm.entity.Power;
import com.yuan.ssm.mapper.PowerMapper;
import com.yuan.ssm.service.PowerService;
import com.yuan.ssm.vo.Page;
@Service
public class PowerServiceImpl implements PowerService {
	@Autowired
	private PowerMapper powerMapper ;

	

//	@Override
//	public boolean update(UserAuthorityEntity user) {
//		if(user!=null) {
//			powerMapper.update(user);
//			return true;
//		}
//		return false;
//	}

	@Override
	public boolean delete(Long id) {
		if(id!=null) {
			powerMapper.delete(id);
			return true;
		}
		return false;
	}

	@Override
	public List<Power> listAll() {
		// TODO Auto-generated method stub
		return powerMapper.listAll();
	}

	@Override
	public Power getByName(String codeNumber) {
		// TODO Auto-generated method stub
		return powerMapper.getByName(codeNumber);
	}

	@Override
	public boolean update(Power user) {
		if(user!=null) {
			powerMapper.update(user);
			return true;
		}
		return false;
	}

	@Override
	public boolean add(Power user) {
		if(user!=null) {
			powerMapper.add(user);
			return true;
		}
		return false;
	}

	@Override
	public Page<Power> listAll(String codeNumber, String operatingAuthorization, int pageNo, int pageSize) {
		Map<String, Object> map = new HashMap<>(10);
		map.put("codeNumber", codeNumber);
		map.put("operatingAuthorization", operatingAuthorization);
		map.put("limit", (pageNo-1)*pageSize);
		map.put("pageSize", pageSize);
		map.put("sort", "PUBLISH_TIME");
		map.put("order", "DESC");
		Page<Power> newPage = new Page<>();
		//查询数量
		newPage.setTotal(powerMapper.listPageCount(map));
		//查询数据
		newPage.setRows(powerMapper.listPage(map));
		return newPage;	}

	
}
